﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Compare two arrays lexicographically</title>
    <link href="styles/js-console.css" rel="stylesheet" />
</head>
<body>
    <div id="js-console"></div>
	<script src="scripts/js-console.js"></script>

    <script>
        var firstArray = [ 'D', 'i', 'a', 'n', 'a' ];
        var secondArray = [ 'P', 'e', 's', 'h', 'o' ];
        var maxLenght;
        var smallerArray;

        if (firstArray.length <= secondArray.length)
        {
            maxLenght = firstArray.length;
        }
        else
        {
            maxLenght = secondArray.length;
        }

        for (var i = 0; i < maxLenght; i++)
        {
            if (firstArray[i] < secondArray[i])
            {
                    smallerArray = 1;
                    break;
            }
            else if (firstArray[i] > secondArray[i])
            {
                    smallerArray = 2;
                    break;
            }
        }

        if (smallerArray == 1)
        {
            jsConsole.writeLine("The first array is earlier.");
        }
        else if (smallerArray == 2)
        {
            jsConsole.writeLine("The second array is earlier.");
        }
        else
        {
            if (firstArray.length > secondArray.length)
        {
                jsConsole.writeLine("The second array is earlier.");
        }
        else if (firstArray.length < secondArray.length)
        {
                jsConsole.writeLine("The first array is earlier.");
        }
        else
        {
                jsConsole.writeLine("The two arrays are the same.");
        }
        }
    </script>
</body>
</html>
